#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (c) 2023, Zühlke Engineering (Austria) GmbH
#
# This file is part of the modm project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# -----------------------------------------------------------------------------

def init(module):
    module.name = ":platform:iwdg"
    module.description = "Independent watchdog"


def prepare(module, options):
    device = options[":target"]

    module.depends(":cmsis:device", ":math:algorithm")
    return device.has_driver("iwdg:stm32")


def build(env):
    env.outbasepath = "modm/src/modm/platform/iwdg"
    # FIXME: Use IWDG2 for second core on STM32H7x5
    env.substitutions = {"core": 1 if env[":target"].identifier.family in ["h7"] else ""}
    env.template("iwdg.hpp.in")
